package com.yiboshi.rehrs.util.js;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Random;

import cn.hutool.core.codec.Base64Encoder;
import com.yiboshi.rehrs.util.js.ContainerUtils;
import kotlin.UByte;
import org.bouncycastle.pqc.jcajce.spec.McElieceCCA2KeyGenParameterSpec;

/* loaded from: classes2.dex */
public class Qi5uxeel {
    private static final String CHAR_LIST = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    private static final char[] CUSTOM_BASE64_CHARS = "qrcklmDoExthWJiHAp1sVYKU3RFMQw8IGfPO92bvLNj.7zXBaSnu0TC6gy_4Ze5d".toCharArray();
    //public static String n1;

    public static String buildN1() {
        return  encode(hexStringToByteArray(generateSHA1(Base64Utils.encode(hexStringToByteArray(generateSHA1(generateRandomPassword(33)).substring(0, 34)))).substring(0, 32))).replace(ContainerUtils.KEY_VALUE_DELIMITER, "");
    }




    //解码
    private static byte[] decode(String encoded) {
        int length = encoded.length();
        int decodedLength = (length * 6 + 7) / 8;
        byte[] decodedBytes = new byte[decodedLength];
        int index = 0;

        for (int i = 0; i < length; i += 4) {
            int block = 0;
            for (int j = 0; j < 4; j++) {
                char c = encoded.charAt(i + j);
                int value = new String(CUSTOM_BASE64_CHARS).indexOf(c);
                if (value == -1) {
                    value = 0; // Handle padding '='
                }
                block = (block << 6) | value;
            }

            for (int j = 0; j < 3 && index + j < decodedLength; j++) {
                decodedBytes[index + j] = (byte) ((block >> (16 - j * 8)) & 0xFF);
            }
            index += 3;
        }

        return decodedBytes;
    }


    public static String encode(byte[] bArr) {
        int i;
        int i2;
        int i3;
        int i4;
        int i5;
        StringBuilder sb = new StringBuilder();
        int length = bArr.length;
        int i6 = 0;
        while (i6 < length) {
            if (i6 < length) {
                i = i6 + 1;
                i2 = bArr[i6] & Base64Utils.MAX_VALUE;
            } else {
                i = i6;
                i2 = 0;
            }
            if (i < length) {
                i3 = i + 1;
                i4 = bArr[i] & Base64Utils.MAX_VALUE;
            } else {
                i3 = i;
                i4 = 0;
            }
            if (i3 < length) {
                i5 = bArr[i3] & Base64Utils.MAX_VALUE;
                i3++;
            } else {
                i5 = 0;
            }
            int i7 = i2 >> 2;
            int i8 = ((i2 & 3) << 4) | (i4 >> 4);
            int i9 = ((i4 & 15) << 2) | (i5 >> 6);
            int i10 = i5 & 63;
            char[] cArr = CUSTOM_BASE64_CHARS;
            sb.append(cArr[i7]);
            sb.append(cArr[i8]);
            char c = '=';
            sb.append(i3 + (-1) < length ? cArr[i9] : '=');
            if (i3 < length) {
                c = cArr[i10];
            }
            sb.append(c);
            i6 = i3;
        }
        return sb.toString();
    }

    public static byte[] hexStringToByteArray(String str) {
        int length = str.length();
        if (length % 2 != 0) {
            throw new IllegalArgumentException("Hex string length must be even.");
        }
        byte[] bArr = new byte[length / 2];
        for (int i = 0; i < length; i += 2) {
            bArr[i / 2] = (byte) ((Character.digit(str.charAt(i), 16) << 4) + Character.digit(str.charAt(i + 1), 16));
        }
        return bArr;
    }

    public static String generateSHA1(String str) {
        try {
            byte[] digest = MessageDigest.getInstance(McElieceCCA2KeyGenParameterSpec.SHA1).digest(str.getBytes());
            StringBuilder sb = new StringBuilder();
            for (byte b : digest) {
                sb.append(String.format("%02x", Byte.valueOf(b)));
            }
            return sb.toString();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
            return null;
        }
    }

    public static String generateRandomPassword(int i) {
        Random random = new Random();
        StringBuilder sb = new StringBuilder();
        for (int i2 = 0; i2 < i; i2++) {
            sb.append(CHAR_LIST.charAt(random.nextInt(62)));
        }
        return sb.toString();
    }

    public static void main(String[] args) {
        String s = buildN1();
        System.out.println(s);
        System.out.println(decode(s));

    }



}